<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type='text/javascript' src='../vue.js'></script>
    <script type='text/javascript' src='../dayjs.min.js'></script>
    
</head>
<body>
    <!-- 
     当监视的属性是数组(数组内容为基本数据类型),
     数组内容的通过array[0]index修改,
     watch属性就算deep为true也无法监视到,需要使用this.$set 或 Vue.set,
     当监视的属性是 数组里的对象 或者 数组里的数组(包含的非基本类型)可以成功监听,
     看vue身上的属性是否包含get(reactiveGetter()) 和 set(reactiveSetter(newVal)) -->
    <div id="root">
        <span>{{arr}}</span>
        <br>
        <button @click="touchMe">touchMe</button>
        <button @click="touchMe2">touchMe2</button>
    </div>

    <script type='text/javascript'>
       let a = new Vue({ 
            el: '#root',
            data: {
                arr:['akk','wkk',{a:10}]
            },
            methods: {
                touchMe(){
                   const fmt = 'YYYY年MM月DD日 HH时mm分ss秒';
                   const dataStr = dayjs(Date.now()).format(fmt);
                   this.arr[0] = dataStr
                   this.$set(this.arr,0,dataStr)
                   console.log(this.arr);
                },
                touchMe2(){
                     this.arr[2].a = Math.random()
                }
            },
            watch: {
                arr: {
                    deep:true,
                    immediate:true,
                    handler(newVal){
                        console.log("--------")
                        console.log(this)
                    }
                }
            }
    
        })
    </script>
    
</body>
</html>